package com.dai.spec.gxk.controller;

import com.dai.spec.common.annotation.Log;
import com.dai.spec.common.core.controller.BaseController;
import com.dai.spec.common.core.page.TableDataInfo;
import com.dai.spec.common.enums.BusinessType;
import com.dai.spec.common.enums.CourseType;
import com.dai.spec.common.enums.DeliveryType;
import com.dai.spec.common.utils.poi.ExcelUtil;
import com.dai.spec.gxk.request.StudentScorePageRequest;
import com.dai.spec.gxk.service.StudentScoreService;
import com.dai.spec.gxk.vo.StudentScoreVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 所有学生成绩信息管理Controller
 * 教务管理员接口，管理所有学生已选课程的成绩信息
 * @author daikl
 * @date 2024-03-12
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/gxk/studentScore")
@Api("所有学生成绩管理")
public class StudentScoreController extends BaseController {

    private StudentScoreService studentScoreService;

    public StudentScoreController(StudentScoreService studentScoreService) {
        this.studentScoreService = studentScoreService;
    }

    /**
     * 查询所有学生成绩列表
     */
    @ApiOperation("查询我的成绩列表")
    @PreAuthorize("@ss.hasPermi('gxk:studentScore:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentScorePageRequest pageRequest) {

        List<StudentScoreVO> list = studentScoreService.queryScoreList(pageRequest);
        return getDataTable(list);
    }
    /**
     * 导出所有成绩信息管理列表
     */
    @ApiOperation("导出所有的成绩列表")
    @PreAuthorize("@ss.hasPermi('gxk:studentScore:export')")
    @Log(title = "所有学生成绩信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentScorePageRequest pageRequest) {

        List<StudentScoreVO> list = studentScoreService.queryScoreList(pageRequest);
        List<StudentScoreVO> studentScoreVOList = list.stream().map(item -> {
            item.setDeliveryType(DeliveryType.getValueByCode(item.getDeliveryType()));
            item.setType(CourseType.getValueByCode(item.getType()));
            return item;
        }).collect(Collectors.toList());
        ExcelUtil<StudentScoreVO> util = new ExcelUtil<>(StudentScoreVO.class);
        util.exportExcel(response, studentScoreVOList, "所有学生的成绩信息管理数据");
    }
}
